<template>
  <div id="app">
    <transition>
      <keep-alive :include="keepAliveComponents">
        <router-view></router-view>
      </keep-alive>
    </transition>
    <van-tabbar v-model="active" route v-if="showTabbar">
      <van-tabbar-item
        v-for="item in menu"
        :key="item.path"
        :icon="item.icon"
        :badge="item.path == '/cart' ? length : null"
        :to="item.path"
        >{{ item.text }}</van-tabbar-item
      >
    </van-tabbar>
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
export default {
  name: "App",
  data() {
    return {
      active: 0,
      showTabbar: true,
      res: "",
      menu: [
        { icon: "wap-home-o", path: "/home", text: "首页" },
        { icon: "orders-o", path: "/sort", text: "分类" },
        { icon: "eye-o", path: "/worth", text: "值得买" },
        {
          icon: "cart-o",
          path: "/cart",
          text: "购物车",
        },
        { icon: "user-o", path: "/mine", text: "个人" },
      ],
      keepAliveComponents: ["Discover", "Mine", "Searchgoods"],
    };
  },
  created() {},
  async updated() {
    const res = await this.cartlength(this.userinfo);
    this.res = res;
  },
  components: {},
  computed: {
    ...mapState("cart", ["cartlist"]),
    ...mapState("user", ["userinfo", "length"]),
  },
  methods: {
    ...mapActions("user", ["cartlength"]),
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
}
/* 从左边进入 */
.v-enter {
  transform: translate(-100%, 0);
}
.v-enter-active {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  transition: transform 0.3s ease-in-out;
}
.v-enter-to {
  transform: translate(0, 0);
}
svg {
  width: 100px;
  height: 30px;
}
</style>
